# 二级分类搜索商品
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains


class PageEcshopFrontSecondaryGoods():
    '''二级分类搜索商品'''
    def __init__(self, driver):
        self.driver = driver

    # 定义定位器
    loc_front_Back_to_home = (By.CLASS_NAME, 'logo_new')
    loc_front_secondary_goods_cart_diamond = (By.XPATH, '//div[@id="HandleLI2_1"]/a')
    loc_front_secondary_goods_cart_leisure = (By.XPATH, '//dd[@id="DisSub2_1"]/div[4]/a[5]')
    loc_front_search_goods = (By.XPATH, '//div[@id="ur_here"]/a[4]')

    # 回到首页
    def front_Back_to_home(self):
        self.driver.find_element(*self.loc_front_Back_to_home).click()

    # 悬停在钻石
    def front_secondary_goods_cart_diamond(self):
        diamond = self.driver.find_element(*self.loc_front_secondary_goods_cart_diamond)  # 定位钻石
        action = ActionChains(self.driver)  # 实例化ActionChains
        action.move_to_element(diamond).perform()

    # 点击二级商品分类
    def front_secondary_goods_cart_leisure(self):
        self.driver.find_element(*self.loc_front_secondary_goods_cart_leisure).click()

    # 断言:休闲西裤
    def front_search_goods(self):
        sgoods = self.driver.find_element(*self.loc_front_search_goods).text
        return sgoods

    def secondary_search(self):
        self.front_Back_to_home()
        self.front_secondary_goods_cart_diamond()
        self.front_secondary_goods_cart_leisure()
        sgoods = self.front_search_goods()
        return sgoods
